package net.starwifi.duobao.service.impl;

import net.starwifi.duobao.service.SettingService;
import net.starwifi.duobao.service.WXUserService;
import net.starwifi.wx.api.UserAPI;
import net.starwifi.wx.dto.UserInfoByCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2016/1/27.
 */
@Service
public class WXUserServiceImpl implements WXUserService {

    @Autowired
    SettingService settingService;


    public String getUserAuthUrl(String redirectUri,String scope,String state){
        String appid=settingService.findByCode("wx_appid").getConfigValue();
        return UserAPI.getUserAuthUrl(appid,redirectUri,"code",scope,state);
    }

    public UserInfoByCode getUserInfo(String code){
        String appid=settingService.findByCode("wx_appid").getConfigValue();
        String appsecret=settingService.findByCode("wx_appsecret").getConfigValue();
        String wBack=UserAPI.getUserAccessToken(appid,appsecret,code);
        return UserInfoByCode.fromJson(wBack);
    }

}
